<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home-page></home-page>
  </div>
  <script src="./vue.js"></script>
  <script src="./axios.js"></script>
  <script>
    const Home = {
      template: `
        <div>
          <h2>这是home页</h2>  
          <ul>
            <li v-for="banner in banners" :key="banner.id">
              <img :src="banner.picUrl"/>
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          // 1data定义初始值
          banners: []
        }
      },
      methods: {
        // 2methods 封装方法 发送请求
        fetchBanners(){
          axios.get('https://api.it120.cc/conner/banner/list').then(res => {
            if(res.data.code === 0) {
              this.banners = res.data.data
            }
          })
        }
      },
      created () {
        // 在合适生命周期钩子函数中调用
        this.fetchBanners();
      }
     
    }
    Vue.component('HomePage', Home)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>